package train.DAY625;


import java.util.HashMap;
import java.util.Map;

public class LeetCode625 {
    public static void main(String[] args) {
//    String a="abc";
//    String b="pqr";
//    String s = mergeAlt(a, b);
//    System.out.println(s);
//        String s="(al)G(al)()()G";
//        System.out.println(interpret(s));
        String a="leetcode";

        System.out.println(reverVowel(a));
    }

    //交替合并字符串
    public static String mergeAlt(String word1,String word2){
        char[] a=new char[word1.length()+word2.length()];
        String c ="";
        int index=0;
        int i=0;
        int length=word1.length()>word2.length()?word2.length():word1.length();
        for (i=0;i<length;i++){
            a[index]=word1.charAt(i);
             index++;
             a[index]=word2.charAt(i);
             index++;
        }
        if(i==word1.length()){
            for (int j = i; j <word2.length(); j++) {
                a[index]=word2.charAt(j);
                index++;
            }
        }
        if(i==word2.length()){
            for (int j = i; j <word1.length(); j++) {
                a[index]=word1.charAt(j);
                index++;

            }
        }
        String s = new String(a);

        for (int j = 0; j < a.length; j++) {
            c=c+a[j];
        }

        return c;
    }

    //设计Goal解析器
    public static String interpret(String command){
        String s="";
        int i=0;
        for(i=0;i<command.length()-1;i++){
            if(command.charAt(i)=='G') s=s+'G';
            if(command.charAt(i)=='('){
                if(command.charAt(i+1)==')')
                {
                    s=s+'o';i++;
                }else{
                    s=s+"al";
                    i+=3;
                }
            }
        }
        if(command.charAt(command.length()-1)=='G')
            s+='G';
        return s;
    }

    //找不同字符
    public static char findDiff(String s,String t){
        char[] chars = s.toCharArray();
        char[] charst = t.toCharArray();
        change(chars);
        change(charst);
        for (int i = 0; i < chars.length; i++) {
            if(chars[i]!=charst[i]) return charst[i];
        }

        return charst[charst.length-1];
    }

    public static char[] change(char[] a){
        char temp;
        for (int i = 1; i < a.length; i++) {
            for (int j = 0; j < a.length-i; j++) {
                if(a[j]>a[j+1]){
                    temp=a[j];
                    a[j]=a[j+1];
                    a[j+1]=temp;
                }
            }
        }
        return a;
    }

    //单词规律
    public static boolean wordPattern(String pattern,String s){
        char[] chars = pattern.toCharArray();
        String[] s1 = s.split(" ");
        boolean k=true;
        Map<Character, String> map = new HashMap<>();
        Map<String, Character> map1 = new HashMap<>();
        if(chars.length!=s1.length) return false;
        for (int i = 0; i < chars.length; i++) {
            if(map.containsKey(chars[i])&&!map.get(chars[i]).equals(s1[i])){
                   return false;
            }else{
                map.put(chars[i],s1[i]);
            }

        }

        for (int i = 0; i < s1.length; i++) {
            if(map1.containsKey(s1[i])&&!map1.get(s1[i]).equals(chars[i])){
                return false;
            }else{
                map1.put(s1[i],chars[i]);
            }
        }
        return k;
    }

    //反转字符串
    public void reverString(char[] s){
        char temp;
        for (int i = 0; i < s.length/2; i++) {
            temp=s[i];
            s[i]=s[s.length-1-i];
            s[s.length-1-i]=temp;
        }

    }

    //反转字符串中的元音字母
    public static String reverVowel(String s){
        char[] chars = s.toCharArray();
        int begin=0;
        int end=s.length()-1;
        char temp;
        while (begin<end){
            while(begin<s.length()){
                if(!isExest(s.charAt(begin))){
                    begin++;
                }else break;
            }
            while(end>=0){
                if(!isExest(s.charAt(end))){
                    end--;
                } else break;
            }
            if(begin<end){
                temp=s.charAt(begin);
                chars[begin]=s.charAt(end);
                chars[end]=temp;
                begin++;
                end--;
            }

        }
        return new String(chars);
    }

    public static boolean isExest(char s){
      String k="aeiouAEIOU";
        for (int i = 0; i < k.length(); i++) {
            if(k.charAt(i)==s) return true;
        }
        return false;
    }
}
